package simulationSupport;

public class ParamRandom {
	
	double [] targets;
	double [] intervals;
	
	
	public ParamRandom(double initialNum,double increment,double[] prob)
	{
		int n = prob.length;
		//1 : Generate targets
		this.targets = new double[n];
		targets[0] = initialNum;
		for(int i=1;i<n;i++)
			targets[i] = targets[i-1] + increment;
		//2: generate intervals
		intervals = new double[2*n];
		intervals[0] = 0.00;
		intervals[1] = (prob[0]*100);
		for(int j=2;j<(n*2);j=j+2)
		{
			intervals[j] = intervals[j-1] ;
			intervals[j+1] = intervals[j-1] + (prob[j/2]*100);
		}
		intervals[intervals.length-1] = 100;
		
	}
	public void testOutput()
	{
		System.out.println("Targets:");
		for (double i:targets)
		{
			System.out.println(i);
			
		}
		System.out.println("Intervals");
		for(int j=0;j<(intervals.length);j=j+2)
			System.out.println(intervals[j]+ " -->"+ intervals[j+1]);
		
		System.out.println("End \n\n\n");
	}
	
	public double getRandomedTarget()
	{
		double rand = Math.random()*100;
		for (int i=0;i<intervals.length;i=i+2)
		{
			if(rand >= intervals[i] && rand <= intervals[i+1]){
				//System.out.println(i);
				return (targets[i/2]);
				
			}
				//resl = targets[i/2];
			
		}
		System.out.println("Failed Rand : "+rand);
		return targets[0];
	}
	 

}
